From 9c391e7a9f6b5baca8ad8e6ecd57a17bf5e2ba37 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 19 Oct 2017 12:01:02 +0200 Subject: [PATCH] Optimize away trivial opacities No need to go color matrix on an opacity of 0 or 1. --- gtk/gtksnapshot.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 2f72614443..4413667912 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -288,11 +288,22 @@ gtk_snapshot_collect_opacity (GtkSnapshot *snapshot, if (node == NULL) return NULL; - opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity); - if (name) - gsk_render_node_set_name (opacity_node, name); - - gsk_render_node_unref (node); + if (state->data.opacity.opacity == 1.0) + { + opacity_node = node; + } + else if (state->data.opacity.opacity == 0.0) + { + gsk_render_node_unref (node); + opacity_node = NULL; + } + else + { + opacity_node = gsk_opacity_node_new (node, state->data.opacity.opacity); + if (name) + gsk_render_node_set_name (opacity_node, name); + gsk_render_node_unref (node); + } return opacity_node; } @@ -324,7 +335,7 @@ gtk_snapshot_push_opacity (GtkSnapshot *snapshot, current_state->translate_x, current_state->translate_y, gtk_snapshot_collect_opacity); - state->data.opacity.opacity = opacity; + state->data.opacity.opacity = CLAMP (opacity, 0.0, 1.0); } static GskRenderNode * -- 2.30.2